//
//  lxStringUtility.m
//  luodansc
//
//  Created by 倫 星 on 2012/10/03.
//  Copyright (c) 2012年 方正株式会社. All rights reserved.
//

#import "lxStringUtility.h"

@implementation lxStringUtility

+ (NSString *)nil2String:(NSString *)theString {
	NSString *str_tmp;
	if (nil == theString) {
		str_tmp = @"";
	}else {
		str_tmp = theString;
	}
	return str_tmp;
}

+ (NSString *)stringTrim:(NSString *)theString {
    if (nil == theString) {
        return nil;
    }
    
    NSString *str_tmp = [theString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    return str_tmp;
}

+ (NSString *)stringClearSpace:(NSString *)theString {
    if (nil == theString) {
        return nil;
    }

    NSCharacterSet *whitespaces = [NSCharacterSet whitespaceCharacterSet];
    NSPredicate *noEmptyStrings = [NSPredicate predicateWithFormat:@"SELF != ''"];
    
    NSArray *parts = [theString componentsSeparatedByCharactersInSet:whitespaces];
    NSArray *filteredArray = [parts filteredArrayUsingPredicate:noEmptyStrings];
    NSString *str_tmp = [filteredArray componentsJoinedByString:@" "];
    return str_tmp;
}

+ (BOOL)isNil:(NSString *)theString {
    if (nil == theString) {
        return YES;
    }
    if ([theString isEqualToString:@""]) {
        return YES;
    }
    return NO;
}

@end
